package com.sudo.api._admin;

import com.sudo.common.utils.HttpUserInfoUtil;
import com.sudo.common.utils.JsonRes;
import com.sudo.common.utils.PagedGridResult;
import com.sudo.dao.admin.model.bo.SysUserBehaviorBO;
import com.sudo.dao.admin.model.bo.SysUserLoginRecordBO;
import com.sudo.service.admin.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(value = "用户行为统计",tags = {"统计登录操作信息接口"})
@RestController
@RequestMapping("userBehavior")
public class StsUserBehaviorController extends AdminBaseController {

    @Resource
    private SysUserBehaviorService sysUserBehaviorService;
    @Resource
    private SysUserLoginRecordService sysUserLoginRecordService;

    @ApiOperation(value = "分页查询用户行为记录",notes = "分页查询用户行为记录",httpMethod = "GET")
    @GetMapping("/queryUserBehaviorByPage")
    public JsonRes queryUserBehaviorByPage(SysUserBehaviorBO sysUserBehaviorBO) {
        PagedGridResult pagedGridResult = sysUserBehaviorService.queryUserBehaviorByPage(sysUserBehaviorBO);
        return JsonRes.ok(pagedGridResult);
    }

    @ApiOperation(value = "分页查询我的行为记录",notes = "分页查询我的行为记录",httpMethod = "GET")
    @GetMapping("/queryMyBehaviorByPage")
    public JsonRes queryMyBehaviorByPage(SysUserBehaviorBO sysUserBehaviorBO,
                                         HttpServletRequest request) {
        String sessionUser = HttpUserInfoUtil.getSessionUser(request);
        sysUserBehaviorBO.setUsername(sessionUser);
        PagedGridResult pagedGridResult = sysUserBehaviorService.queryUserBehaviorByPage(sysUserBehaviorBO);
        return JsonRes.ok(pagedGridResult);
    }

    @ApiOperation(value = "分页查询用户登录记录",notes = "分页查询用户登录记录",httpMethod = "GET")
    @GetMapping("/queryUserLoginRecordByPage")
    public JsonRes queryUserLoginRecordByPage(SysUserLoginRecordBO sysUserLoginRecordBO) {
        PagedGridResult pagedGridResult = sysUserLoginRecordService.queryUserLoginRecordByPage(sysUserLoginRecordBO);
        return JsonRes.ok(pagedGridResult);
    }

    @ApiOperation(value = "分页查询我的登录记录",notes = "分页查询我的登录记录",httpMethod = "GET")
    @GetMapping("/queryMyLoginRecordByPage")
    public JsonRes queryMyLoginRecordByPage(SysUserLoginRecordBO sysUserLoginRecordBO,
                                            HttpServletRequest request) {
        String sessionUser = HttpUserInfoUtil.getSessionUser(request);
        sysUserLoginRecordBO.setUsername(sessionUser);
        PagedGridResult pagedGridResult = sysUserLoginRecordService.queryUserLoginRecordByPage(sysUserLoginRecordBO);
        return JsonRes.ok(pagedGridResult);
    }

}
